home *** CD-ROM | disk | FTP | other *** search
- Path: plato.ansa.co.uk!news
- From: tms@ansa.co.uk (Toby Speight)
- Newsgroups: comp.lang.c++
- Subject: Stream operators (was Re: well-chosen overloading)
- Date: 6 Mar 1996 12:53:00 GMT
- Organization: ANSA, Cambridge, England.
- Sender: tms@socrates.ansa.co.uk
- Message-ID: <s8spfmv13j.fsf_-_@socrates.ansa.co.uk>
- References: <313613B2.136E@ksopk.sprint.com>
- <4h554t$9jk@netline-fddi.jpl.nasa.gov> <4h8ka3$4o8@atlas.tus.ssi1.com>
- <4hibv9$8bu@mcrware.microware.com>
- NNTP-Posting-Host: socrates.ansa.co.uk
- Mime-Version: 1.0
- Content-Type: text/plain; charset=US-ASCII
- Content-Transfer-Encoding: 7bit
- In-reply-to: jejones@microware.com's message of 5 Mar 1996 21:33:29 GMT
- X-Phone: +44 1223 568925
- X-Fax: +44 1223 359779
- X-Yow: As President I have to go vacuum my coin collection!
- X-Newsreader: Gnus v5.1
-
- -----BEGIN PGP SIGNED MESSAGE-----
-
- I'll take your points in reverse order (you'll see why)
-
- >>>>> In article <4hibv9$8bu@mcrware.microware.com>,
- >>>>> James == "James Jones" <jejones@microware.com> writes:
-
- James> (Come to think of it, while I'm asking about streams, it's
- James> obviously a a good idea to write
-
- James> cout << (i << j);
-
- James> to output the result of shifting i left j bits, but is it
- James> necessary?)
-
- Absolutely. "cout << i << j" means "(cout << i) << j"; in other words
- "output i, then with the resulting stream, output j". For the
- standard streams, the result is the same as the original stream, so
- "cout << i << j" is the same as "cout << i, cout << j"
-
- This was one of the main reasons for the stream "shift" syntax.
-
-
- James> I've always wondered why the stream output operator isn't +=
- James> (-= for input).
-
- Because the precedence of += is much lower (it doesn't bind as
- tightly), and because it has the opposite associativity
- (right-to-left, rather than left-to-right).
-
- "cout << i << j" would become "(cout += i) += j"
-
- which is (arguably) less readable.
-
- See D&E, section 8.3.1 for the rationale on stream operators.
- -----BEGIN PGP SIGNATURE-----
- Version: 2.6.2i
- Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface
-
- iQB1AwUBMT2Jq+dsuUurvcRtAQGJ8AL/V8K2tU5CRGS15MDPjbuk2mvJYbiOg5Lw
- KClxmbTTFfny+6YGlVDJDheO4vX36g12D24nRgbzQVNQCTUE4YXSdaMmWKmadI3O
- UF8pw9FxO5kTJ74RSkCq9Fms76ZQN6R7
- =B+kP
- -----END PGP SIGNATURE-----
- --
- Toby Speight <tms@ansa.co.uk> Phone +44 1223 568925, Fax +44 1223 359779
- APM Ltd., Poseidon House, Castle Park, Cambridge CB3 0RD
-